package com.zone.service.service.impl;

import java.util.List;
import com.zone.common.core.utils.DateUtils;
import com.zone.common.core.utils.StringUtils;
import com.zone.common.core.constant.UserConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zone.service.mapper.DeviceModelMapper;
import com.zone.service.domain.DeviceModel;
import com.zone.service.service.IDeviceModelService;

/**
 * 设备型号Service业务层处理
 * 
 * @author liuyang
 * @date 2025-11-15
 */
@Service
public class DeviceModelServiceImpl implements IDeviceModelService 
{
    @Autowired
    private DeviceModelMapper deviceModelMapper;

    /**
     * 查询设备型号
     * 
     * @param id 设备型号主键
     * @return 设备型号
     */
    @Override
    public DeviceModel selectDeviceModelById(Long id)
    {
        return deviceModelMapper.selectDeviceModelById(id);
    }

    /**
     * 查询设备型号列表
     * 
     * @param deviceModel 设备型号
     * @return 设备型号
     */
    @Override
    public List<DeviceModel> selectDeviceModelList(DeviceModel deviceModel)
    {
        return deviceModelMapper.selectDeviceModelList(deviceModel);
    }

    /**
     * 新增设备型号
     * 
     * @param deviceModel 设备型号
     * @return 结果
     */
    @Override
    public int insertDeviceModel(DeviceModel deviceModel)
    {
        deviceModel.setCreateTime(DateUtils.getNowDate());
        return deviceModelMapper.insertDeviceModel(deviceModel);
    }

    /**
     * 修改设备型号
     * 
     * @param deviceModel 设备型号
     * @return 结果
     */
    @Override
    public int updateDeviceModel(DeviceModel deviceModel)
    {
        deviceModel.setUpdateTime(DateUtils.getNowDate());
        return deviceModelMapper.updateDeviceModel(deviceModel);
    }

    /**
     * 批量删除设备型号
     * 
     * @param ids 需要删除的设备型号主键
     * @return 结果
     */
    @Override
    public int deleteDeviceModelByIds(Long[] ids)
    {
        return deviceModelMapper.deleteDeviceModelByIds(ids);
    }

    /**
     * 删除设备型号信息
     * 
     * @param id 设备型号主键
     * @return 结果
     */
    @Override
    public int deleteDeviceModelById(Long id)
    {
        return deviceModelMapper.deleteDeviceModelById(id);
    }
    
    /**
     * 校验设备型号是否唯一
     *
     * @param deviceModel 设备型号信息
     * @return 结果
     */
    @Override
    public boolean checkDeviceModelUnique(DeviceModel deviceModel)
    {
        Long id = StringUtils.isNull(deviceModel.getId()) ? -1L : deviceModel.getId();
        DeviceModel info = deviceModelMapper.checkDeviceModelUnique(deviceModel.getBrandType(), 
                deviceModel.getDeviceType(), deviceModel.getDeviceModel());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != id.longValue()) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    /**
     * 批量插入设备型号数据
     *
     * @param deviceModelList
     * @return 结果
     */
    @Override
    public int batchInsertDeviceModel(List<DeviceModel> deviceModelList) {
        return deviceModelMapper.batchInsertDeviceModel(deviceModelList);
    }
}